<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    用户名：<input
      type="text"
      id="username"
      autocomplete="off"
      placeholder="请输入关键字"
    />
    <script>
      var userEle = document.getElementById('username');
      // 键盘按下触发
      //   userEle.addEventListener('keydown', function () {
      //     console.log('键盘按下');
      //   });

      //   键盘按下并抬起触发keyup
      userEle.addEventListener('keyup', function (event) {
        // event是事件对象
        console.log('键盘并按下');
        console.log(event.type); // 'keyup'
        // console.log(event.key); // 键的字母
        // console.log(event.keyCode); // 键码
        if (event.keyCode === 13) {
          alert('登录了');
        }
      });
    </script>
  </body>
</html>
